<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var he = 0;
        // 2、求出1-1/2 + 1/3 - 1/4 + 1/5....... 1/100的和
        for (i = 1; 1 <= 100; i++) {
            //  判断是奇数加法运算
            if (i % 2 !== 0) {
                he = he + 1 / i;
            }
            // 判断是偶数减法运算
            else if (i % 2 === 0) {
                he = he - 1 / i;
            }
        }
        console.log(he);
    </script>
</body>

</html>